import Common from "../../Common";
import Td from "./Td";


const {ccclass, property} = cc._decorator;

@ccclass
export default class Tr extends Common {

    protected tdItem: cc.Prefab

    @property(cc.Node)
    content: cc.Node


    async attachTd(val: string | number, width = 200) {
        const tdNode = cc.instantiate(await this.getTdItem())
        tdNode.getComponent(Td).init(`${val}`, width)
        this.content.addChild(tdNode)
    }

    setBgColor(color?: string) {
        if (!color) {
            return
        }
        const _color = cc.Color.fromHEX(cc.color(), color)
        this.content.children.forEach(item => {
            item.active = false
            item.color = _color
            item.active = true
        })
    }

    async getTdItem() {
        if (!this.tdItem) {
            this.tdItem = await this.getPrefab('table/td')
        }
        return this.tdItem
    }
}
